package com.yue.servlet;

import com.yue.component.Mythread;

import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/11/30<br/>
 *
 * @author QiuYang
 */
@WebServlet(name = "asyncServlet", urlPatterns = {"/asyncServlet"}, asyncSupported = true)
public class AsyncServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        PrintWriter out = resp.getWriter();
        out.println("<html>");
        out.println("<body>");
        out.println("++++++++页面开始+++++++++<hr/>");
        AsyncContext asyncContext = req.startAsync();
        asyncContext.addListener(new MyAsyncListener());
        asyncContext.setTimeout(30 * 3000);
        asyncContext.start(new Mythread(asyncContext));
        out.println("++++++++页面结束++++++++++++++");
        out.println("</body>");
        out.println("</html>");
        out.flush();
    }
}
